//
//  VillageRuleViewController.m
//  Cunli
//
//  Created by 湛亚 on 15/12/10.
//  Copyright (c) 2015年 lilubin. All rights reserved.
//

#import "VillageRuleViewController.h"
#import "MyDataService.h"
#import "NSString+MD5.h"

@interface VillageRuleViewController ()<UIWebViewDelegate>{
    
    UIWebView *ruleView;
    float screenWidth;
    float screenHeight;
}

@end

@implementation VillageRuleViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title=@"村规民约";
    self.view.backgroundColor=[UIColor whiteColor];
    
    [self createWebView];
//    [self createNavBtn];
    [self getVillageRule];
}

-(void)createWebView{
    
    screenWidth=[UIScreen mainScreen].bounds.size.width;
    screenHeight=[UIScreen mainScreen].bounds.size.height;
    ruleView=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight-64)];
    ruleView.delegate=self;
    ruleView.scrollView.bounces = NO;
    [self.view addSubview:ruleView];
}

/*
-(void)createNavBtn{
    
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(0, 0, 28, 28);
    leftBtn.contentEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
    [leftBtn setImage:[UIImage imageNamed:@"regback01"] forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
    leftBtn.contentEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
    UIBarButtonItem *leftBarItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
    self.navigationItem.leftBarButtonItem = leftBarItem;
}
 */

-(void)getVillageRule{
    
    NSMutableDictionary *CheckParams =[[NSMutableDictionary alloc]init];
    [CheckParams setObject:[Config getOwnUserID] forKey:@"userid"];
    [CheckParams setObject:[Config getOwnAreaids] forKey:@"areaids"];
    NSString *resultSign = [NSString getSignFromParam:CheckParams andSession:[Config getOwnSession]];
    [CheckParams setObject:resultSign forKey:@"sign"];
    [MyDataService requestURL:@"cgmy_detail.php" httpMethod:@"GET" params:CheckParams fileDatas:nil complection:^(id result) {
        
        NSLog(@"%@",result);
        
        if ([[result objectForKey:@"response"] isEqualToString:@"cgmy_detail"]) {
            
            NSDictionary *dic=[result objectForKey:@"data"];
            if ([dic isEqual:@""]) {
                [Config showHUDWithText:@"无内容!" andImage:@"done"];
                return ;
            }
            
            if ([dic objectForKey:@"content"]) {
                [ruleView loadHTMLString:[dic objectForKey:@"content"] baseURL:nil];
            }else{
                [Config showHUDWithText:@"获取失败!" andImage:@"error"];
            }
            
        }else{
            
            [Config showHUDWithText:@"获取失败!" andImage:@"error"];
        }
        
    }failureAction:^{
        [Config showHUDWithText:@"获取失败!" andImage:@"error"];
    }];
}
/*
-(void)goBack{
    
    [self.navigationController popViewControllerAnimated:YES];
}
*/
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
